package org.xzx.shop_api.utils;

import java.util.HashSet;

public class ImageUtils {

    //图片扩展名验证
    public static Boolean isAllowedExtName(String extName) {
        HashSet<String> extensionSet = new HashSet<String>();
        extensionSet.add("jpg");
        extensionSet.add("jpeg");
        extensionSet.add("png");
        return extensionSet.contains(extName.toLowerCase());
    }

    //获取图片扩展名
    public static String getExtName(String contentType) {
        int pos = contentType.indexOf("/")+1;
        return contentType.substring(pos);
    }
    //图片大小限制
    public static Boolean isAllowedImageSize(long size ) {
        int allowImageSize = 2 *1024*1024;
        if (size > allowImageSize) {
            return false;
        }
        return true;
    }
}
